/*
  ******************************************************************************
  *project：    MOTOR_Control Board Test Project
  *developer：  郑州嵌羚智能科技有限公司 http://emlstech.com/
  *support:     许 (13523443291)
  *data：       2021-01-28
  *CPU：        Atmega328P Arduino UNO R3 16MHz
  *version:     V1.0
  *comment：    两IO(10,11)控制电机转向,PWM(9)控制电机转速
                电机以50%占空比运行，每5秒切换一次转向
  ******************************************************************************
*/
#include <TimerOne.h>

int motor_pwm = 9;
int motor_in1 = 10;
int motor_in2 = 11;
int duty = 512;

void setup() {

  pinMode(motor_pwm, OUTPUT);
  pinMode(motor_in1, OUTPUT);
  pinMode(motor_in2, OUTPUT);

  Timer1.initialize(1000);
  Timer1.pwm(motor_pwm, duty);
  Timer1.start();
}

void loop() {

  digitalWrite(motor_in1, HIGH);    //正转
  digitalWrite(motor_in2, LOW);
  delay(1000); delay(1000); delay(1000); delay(1000); delay(1000);

  digitalWrite(motor_in1, LOW);     //反转
  digitalWrite(motor_in2, HIGH);
  delay(1000); delay(1000); delay(1000); delay(1000); delay(1000);
}
